package com.step.sprite;

import java.util.ArrayList;

import com.step.graphic.Texture;
import com.step.mesh.Mesh;

public class Sprite3DContainer extends Sprite3D implements IContainer{
	public Sprite3DContainer() {
		super(null, null);
		children = new ArrayList<Sprite3D>();
	}
	
	public Sprite3DContainer(Mesh mesh, Texture texture) {
		super(mesh, texture);
		children = new ArrayList<Sprite3D>();
	}

	public Sprite3DContainer(Texture texture) {
		super(texture);
		children = new ArrayList<Sprite3D>();
	}



	@Override
	public void addChild(Sprite3D sprite) {
		children.add(sprite);
		sprite.parent = this;
	}

	@Override
	public void addChildAt(Sprite3D sprite, int index) {
		children.add(index, sprite);
		sprite.parent = this;
	}

	@Override
	public boolean remove(Sprite3D sprite) {
		boolean b = children.remove(sprite);
		if(b) sprite.parent = null;
		
		return b;
	}

	@Override
	public Sprite3D remove(int index) {
		Sprite3D sprite3d = children.remove(index);
		
		if(sprite3d != null) sprite3d.parent = null;
		
		return sprite3d;
	}

	@Override
	public Sprite3D getChild(int index) {
		return children.get(index);
	}

	@Override
	public Sprite3D getChild(String name) {
		int len = children.size();
		
		for (int i = 0; i < len; i++) {
			Sprite3D sprite3d = children.get(i);
			
			if(sprite3d.getName().equals(name)){
				return sprite3d;
			}
		}
		
		return null;
	}

	@Override
	public int indexOf(Sprite3D sprite) {
		return indexOf(sprite);
	}

	@Override
	public int size() {
		return children.size();
	}

	@Override
	public boolean is2D() {
		return mesh.is2D();
	}

	@Override
	public boolean is3D() {
		return mesh.is3D();
	}

}
